<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="com.sz.ticket.dao.ITicketDAO" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String style1 = "width: 150px;text-align:right;font-size: 12px;";
String style2 = "text-align:left;width: 294px";

ServletContext servletContext = request.getSession().getServletContext(); 
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ITicketDAO dao = (ITicketDAO) context.getBean("TicketDAO");
List list = dao.queryTicketStatusList();

String usertype = request.getSession().getAttribute("usertype").toString();
String regionid = request.getSession().getAttribute("regionid").toString();
String ticket_id = request.getParameter("ticket_id");
if(ticket_id == null || ticket_id.trim().length() == 0) ticket_id="0";
%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	    <link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>">

		<title>订单日志</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="viewTicketLog">
		<meta http-equiv="description" content="订单日志">
		
		<style type="text/css"> 
			@import "js/tableview/TableView.css";
			
	
    	</style>
	</head>
	
	<body>
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/tableview/SortView.js"></script>
		<script type="text/javascript" src="js/tableview/PagerView.js"></script>
		<script type="text/javascript" src="js/tableview/TableView.js"></script>
		<script type="text/javascript" src="js/tableview/SelectorView.js"></script>
		<script type="text/javascript" src="js/tableview/PaperView.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
		<script type="text/javascript" src="js/calendar.js"></script>
		<table width="100%" height="50px" border="0" cellpadding="0" cellspacing="0">
	  	 
	  	   		<tr>
		  	<td class="title0">订单日志</td>
		  	
	  	</tr>
	  	</table>		

	  	<div id="table_div" style= "width: 100%"></div>
		<div id="pager" style="display:none"></div>
		
		<script type="text/javascript">
		
		var numPerPage = 10; //每页行数
		var paramValue = ""; //形如  "{STATUS:'1', CREATE_MANAGER:'1'}"
		var methodCount = "";
		var methodPage = "";
		
		var table = new TableView('table_div');
		table.header = {
		    IID					: '',
			TICKET_ID			: '订单编号',
			STATUS_NAME			: '订单状态',
			CUST_TEL			: '客户电话',
			CUST_NAME			: '客户姓名',
			BUSINESS_NAME		: '商家名称',
			DEMAND_TIME_STR		: '预约时间',
			OPERATOR_NAME		: '操作员',			
			VERSION_STR	        : '操作时间',
			CONFIRM_B_STR		: '商家确认',
			CONFIRM_C_STR		: '客户确认',		
			DETAIL				: '详细信息'
		
		};		
		table.customDefine = {
				IID					: 'style="display:none"',
				TICKET_ID			: 'width = "60px"',
				STATUS_NAME			: 'width = "120px"',
				CUST_TEL			: 'width = "100px"',
				CUST_NAME			: 'width = "100px"',
				BUSINESS_NAME		: 'width = "120px"',
				DEMAND_TIME_STR		: '',
				OPERATOR_NAME		: '',
				VERSION_STR	        : '',				
				CONFIRM_B_STR		: '',
				CONFIRM_C_STR		: '',				
				DETAIL				: ''					
		};
				
		table.dataKey = 'TICKET_ID';
		table.display.multiple = false;
		table.count = false;
		table.title = false;
		table.display.filter = false;
		table.display.pager = false;
		table.pager.size = numPerPage;

		var pager = new PagerView('pager');
		pager.onclick = onPagerClick;
		pager.itemCount = 0;
		pager.size = numPerPage;
		
		table.render();
		pager.render();

		function queryTicket(pageNO, returnCount) {
  	  		var begin = (pageNO-1) * numPerPage + 1;
  	  		var end = pageNO * numPerPage;
  	  		var mc = returnCount==true ? methodCount : "";
  	  		var date = {
  	  			BEAN_METHOD 	: "TicketBMO.queryTicketLog",
  	  			PARAM_CLASS 	: "java.util.Map",
  	    	  	PARAM_VALUE 	: paramValue,
  	    	  	METHOD_COUNT 	: mc, //为空则不返回记录数
  	    	  	METHOD_PAGE 	: methodPage, //为空则不分页
  	    	  	PAGE_BEGIN 		: begin, //仅在METHOD_PAGE不为空时使用
  	    	  	PAGE_END 		: end
  	  	    };
  	  		$.ajax({
				type: "POST",
				url: "query.exec",
				//data: {id:'123'},
				data: date,
				datatype:"json",
				success: query_success,
				error: show_error
  	  		});

  	  		/*
  			var ids = table.getSelectedKeys();
  			table.pager.size = 6;
  			
  			table.clear();
  			table.add({id: 2, name: 'kao2', name_cn: '杰瑞', text: 'Jerrimy'}); 
  			table.add({id: 3, name: 'kao3', name_cn: '杰瑞', text: 'Jerrimy'}); 
			var range = new Array(5);
			range.push({id: 40, name: 'kao', name_cn: '幽灵', text: 'None'});
			range.push({id: 60, name: 'kao', name_cn: '幽灵', text: 'None'});
			table.addRange(range);*/
  			return true;
  			
  		}
  		
  		function onPagerClick(pageNO) {
  			queryTicket(pageNO, "FLASE");
  		}
  		
  		//刷新当前页
  		function refreshCurrentPage() {
  			queryTicket(pager.index, "FLASE");
  		}

  		function query_success(data) {
  	  		var jdata = eval("(" + data + ")");
  	  		if(jdata.COUNT != null) { //有记录数返回  	  	  		
  	  	  		pager.itemCount = jdata.COUNT;
  	  	  		pager.size = numPerPage;  	  	  		
  	  	  		pager.render();
  	  		} 
		   var array = eval(jdata.LIST);
		   for(var i = 0; i < array.length; ++i) {
		   		//形如：<a href="javascript:" onclick="about()">modal</a>
		   		var url = "<a href=\"javascript:\" onclick=\"onClickDetail('";
		   		url += array[i].IID;
		   		url += "','";
		   		url += array[i].TICKET_ID
		   		url += "')\">详细信息</a>";
		   		array[i].DETAIL = url;
		   		
		   		if(array[i].CONFIRM_B == "1") {
		   			array[i].CONFIRM_B_STR = "已确认";
		   		} else if(array[i].CONFIRM_B == "-1"){
		   			array[i].CONFIRM_B_STR = "确认失败";
		   		} else {
		   			array[i].CONFIRM_B_STR = "待确认";
		   		}
		   		if(array[i].CONFIRM_C == "1") {
		   			array[i].CONFIRM_C_STR = "已确认";
		   		} else if(array[i].CONFIRM_C == "-1"){
		   			array[i].CONFIRM_C_STR = "确认失败";
		   		} else {
		   			array[i].CONFIRM_C_STR = "待确认";
		   		}		   		
		   }
		   table.clear();
		   table.addRange(array);
		}
  		function show_error(data) {
  			var err = "操作失败！\n";
  			err += "status：" + data.status + "\n";
  			err += "statusText：" + data.statusText;
  	  		alert(err);
 		}
 		function onClickDetail(hid, ticket_id) {
 		    //hid为空则表示显示订单当前信息,否则显示历史
 		    if(hid.toLowerCase()=="null" || hid.length == 0) {
 		    	onTicketDetail(ticket_id)
 		    } else {
 		    	onTicketDetail_h(hid)
 		    }
 		}  		
  		function onTicketDetail_h(hid) {
   			var url = "<%=path%>";
  			url += "/page/viewTicketLogDetail.jsp?iid=" + hid;
  			var param = "status:no;scroll:no;dialogWidth:1024px;dialogHeight:600px";
			//window.showModalDialog(url, window, param);
			
			var width = 1024; //弹出窗口的宽度;
			var height = 600; //弹出窗口的高度;
			var top = (window.screen.availHeight-30-height)/2; //获得窗口的垂直位置;
			var left = (window.screen.availWidth-10-width)/2; //获得窗口的水平位置;
			var style = "toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no";			
			window.open (url,"订单信息","height="+height+",width="+width+",top="+top+",left="+left+","+style); 			
  		}
  		function onTicketDetail(ticket_id) {
   			var url = "<%=path%>";
  			url += "/page/viewTicket.jsp?ticket_id=" + ticket_id;
  			var param = "status:no;scroll:no;dialogWidth:1024px;dialogHeight:600px";
			//window.showModalDialog(url, window, param);
			
			var width = 1024; //弹出窗口的宽度;
			var height = 600; //弹出窗口的高度;
			var top = (window.screen.availHeight-30-height)/2; //获得窗口的垂直位置;
			var left = (window.screen.availWidth-10-width)/2; //获得窗口的水平位置;
			var style = "toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no";			
			window.open (url,"订单信息","height="+height+",width="+width+",top="+top+",left="+left+","+style); 			
  		}  		
 		function showMsg(data) {
  	  		alert(data);
 		} 		
 		
 		function onQuery(ticket_id){
			var tmp;
			paramValue = "{";			
			
			//region
  			paramValue += " TICKET_ID:'" + "<%=ticket_id%>";
			paramValue += "'";
			paramValue += ",";  			
			
			paramValue += " __ORDERBY:'order by t.version desc'";  			
  			  			
  			paramValue += "}";
  				
  	  		pager.index = 1;
  	  		queryTicket(1, false);
 		}
 		
 		onQuery("<%=ticket_id%>");
	</script>
	
	</body>
</html>
